package com.example.usagelock;

import java.util.Arrays;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.example.surfaceball.R;

public class ImageManager {
	static final int NumberOfImageType = 11;
	static final int NumberOfImageStyle = 3;
	
	static Context mContext;
	static Resources mResources;
	static ImageManager mImageManager;
	
	Bitmap[][] mImageList;
	
	private ImageManager(){
		mImageList = new Bitmap[NumberOfImageType][NumberOfImageStyle];
		initilizeImages();
	}
	
	private Bitmap getBitmap(int id){
		return BitmapFactory.decodeResource(mResources, id);
	}
	
	private void initilizeImages(){
		mImageList[ImageType.Config][ImageStyle.Fill] 		= getBitmap(R.drawable.config_fill);
		mImageList[ImageType.Config][ImageStyle.Normal] 	= getBitmap(R.drawable.config_normal);		
		mImageList[ImageType.Config][ImageStyle.Nothing] 	= getBitmap(R.drawable.config_nothing);
		
		mImageList[ImageType.Glasses][ImageStyle.Fill] 		= getBitmap(R.drawable.glasses_fill);
		mImageList[ImageType.Glasses][ImageStyle.Normal] 	= getBitmap(R.drawable.glasses_normal);
		mImageList[ImageType.Glasses][ImageStyle.Nothing] 	= getBitmap(R.drawable.glasses_nothing);
		
		mImageList[ImageType.Heart][ImageStyle.Fill] 		= getBitmap(R.drawable.heart_fill);
		mImageList[ImageType.Heart][ImageStyle.Normal] 		= getBitmap(R.drawable.heart_normal);
		mImageList[ImageType.Heart][ImageStyle.Nothing] 	= getBitmap(R.drawable.heart_nothing);
		
		mImageList[ImageType.Key][ImageStyle.Fill] 			= getBitmap(R.drawable.key_fill);
		mImageList[ImageType.Key][ImageStyle.Normal] 		= getBitmap(R.drawable.key_normal);
		mImageList[ImageType.Key][ImageStyle.Nothing] 		= getBitmap(R.drawable.key_nothing);
		
		mImageList[ImageType.Memo][ImageStyle.Fill] 		= getBitmap(R.drawable.memo_fill);
		mImageList[ImageType.Memo][ImageStyle.Normal] 		= getBitmap(R.drawable.memo_normal);
		mImageList[ImageType.Memo][ImageStyle.Nothing] 		= getBitmap(R.drawable.memo_nothing);
		
		mImageList[ImageType.Note][ImageStyle.Fill] 		= getBitmap(R.drawable.note_fill);
		mImageList[ImageType.Note][ImageStyle.Normal] 		= getBitmap(R.drawable.note_normal);
		mImageList[ImageType.Note][ImageStyle.Nothing] 		= getBitmap(R.drawable.note_nothing);
		
		mImageList[ImageType.Pencil][ImageStyle.Fill] 		= getBitmap(R.drawable.pencil_fill);
		mImageList[ImageType.Pencil][ImageStyle.Normal] 	= getBitmap(R.drawable.pencil_normal);
		mImageList[ImageType.Pencil][ImageStyle.Nothing] 	= getBitmap(R.drawable.pencil_nothing);
		
		mImageList[ImageType.Phone][ImageStyle.Fill] 		= getBitmap(R.drawable.phone_fill);
		mImageList[ImageType.Phone][ImageStyle.Normal] 		= getBitmap(R.drawable.phone_normal);
		mImageList[ImageType.Phone][ImageStyle.Nothing] 	= getBitmap(R.drawable.phone_nothing);
		
		mImageList[ImageType.Puzzle][ImageStyle.Fill] 		= getBitmap(R.drawable.puzzle_fill);
		mImageList[ImageType.Puzzle][ImageStyle.Normal] 	= getBitmap(R.drawable.puzzle_normal);
		mImageList[ImageType.Puzzle][ImageStyle.Nothing] 	= getBitmap(R.drawable.puzzle_nothing);
		
		mImageList[ImageType.Star][ImageStyle.Fill] 		= getBitmap(R.drawable.star_fill);
		mImageList[ImageType.Star][ImageStyle.Normal] 		= getBitmap(R.drawable.star_normal);
		mImageList[ImageType.Star][ImageStyle.Nothing] 		= getBitmap(R.drawable.star_nothing);
		
		mImageList[ImageType.Thunder][ImageStyle.Fill] 		= getBitmap(R.drawable.thunder_fill);
		mImageList[ImageType.Thunder][ImageStyle.Normal] 	= getBitmap(R.drawable.thunder_normal);
		mImageList[ImageType.Thunder][ImageStyle.Nothing] 	= getBitmap(R.drawable.thunder_nothing);
	}
	
	public static ImageManager getInstance(Context context){
		if(mImageManager == null){
			mContext = context;
			mResources = mContext.getResources();
			mImageManager = new ImageManager();
		}
		return mImageManager;
	}
	
	public Bitmap getImage(int imageType, int imageStyle){
		if((imageType < 0 && imageType >= NumberOfImageType)
				&& (imageStyle < 0 && imageStyle >= NumberOfImageStyle)){
			throw new NotFoundImageException();
		}
		return mImageList[imageType][imageStyle]; 
	}
	
	public Bitmap[] getImages(int imageType){
		if(imageType < 0 && imageType >= NumberOfImageType){
			throw new NotFoundImageException();
		}
		return mImageList[imageType];
	}
	
	public void getImages(int imageType, Bitmap[] outImages){
		if(imageType < 0 && imageType >= NumberOfImageType){
			throw new NotFoundImageException();
		}
		outImages = Arrays.copyOf(mImageList[imageType], NumberOfImageStyle);
	}
	
	public void setImages(Label label, int imageType){
		label.setImage(mImageList[imageType]);
		label.setImageType(imageType);
	}
}